import {
    setToken,
    getToken,
    setUser,
    setTokenType
} from '@/utils/common';
import {
    message
} from '@/utils/resetMessage';
export default {
    state: {
        token: getToken(),
        userInfo: '',
        permissions: [],
        pageLoading: false,
    },
    mutations: {
        setUser(state, data) {
            state.userInfo = data
        },
        setPermissions(state, data) {
            state.permissions = data
        },
        setPageLoading(state, value) {
            state.pageLoading = value
        },
    },
    actions: {
        // 登录
        handleLogin({
            dispatch,
            commit
        }, {
            form}) {
            return new Promise((resolve, reject) => {
                setToken('toeken1100');
            setTokenType('bareae');
                resolve({})
            })
        },
        //用户信息
        handleUserInfo({
            commit
        }) {
            return new Promise((resolve, reject) => {
                resolve({})
            })
        },
        // 退出登录
        handleLogOut({
            dispatch,
            commit
        }) {
            return new Promise((resolve, reject) => {
                let data = {
                    token_type: "",
                    token: "Bearer",
                    expires_in: 0
                }
                setToken(data);
                setTokenType(data);
                console.log(getToken())
            })
        },
        getAuthority({
            commit
        }) {
            commit('setPageLoading', true)
            return new Promise((resolve, reject) => {
                commit('setPageLoading', false)
                if (res.data.code === 0) {
                    let auths = []
                    let permissions = res.data.data.filter(item => {
                        return item.IsShow === true
                    })
                    permissions.forEach(item => {
                        auths.push(item.ButtonCode)
                    })
                    commit('setPermissions', auths)
                    resolve()
                }
            })
        },
    }
}